<?php


namespace app\admin\controller;


use app\admin\model\BaseModel;
use app\admin\model\MaintenanceProjectModel;
use app\admin\model\OrderGoodsModel;
use app\admin\model\OrderPayLogModel;
use app\admin\model\ProtectPaymentModel;
use app\admin\model\ServiceBuriedModel;
use app\admin\model\ServiceWeibaoModel;
use cmf\controller\AdminBaseController;
use app\admin\model\OrderModel;
use cmf\controller\BaseController;
use cmf\controller\HomeBaseController;
use think\Db;

class StampController extends BaseController
{
    protected $customerId =0;
    protected $tombId =0;
    protected $tomb_type =0;
    protected $tomb_num =0;
    protected $result_list =0;
    protected $dep_list =[];
    protected $users_array =[];
    protected $tomb_typei =0;//0购买；1寄存
    protected $cate_arr=[
        1=>'商品墓',
        2=>'艺术墓',
        3=>'生态墓',
        4=>'节地墓'
    ];
    protected $regulation_arr=[
        0=>'',
        1=>'单穴',
        2=>'双穴',
        3=>'三穴',
    ];
    protected $col_status=[
        0=>'无产品',
        1=>'空闲',
        2=>'保留',
        3=>'定金',
        4=>'无规划',
        5=>'购买未使用',
        6=>'部分安葬',
        7=>'全部安葬',
        8=>'迁出',
    ];

    protected $logo_img = " ";


    public function  initialize()
    {
        $this->customerId = session('aftersale.customer_id');
        $this->tombId = session('aftersale.tomb_id');
        $this->tomb_type = session('aftersale.tomb_type');
        $this->assign('logo_img',$this->logo_img);
        parent::initialize();
    }

    public  function  print_cert(){
        $type=$this->request->param('type');
        $mark=$this->request->param('mark',1);
        $year=date('Y');
        $month=date('m');
        $day=date('d');
        $this->assign(['year'=>$year,'month'=>$month,'day'=>$day]);
        if($mark==1){
            //财务打印
            $pay_id = $this->request->param('pay_id');
            $pay_info = OrderPayLogModel::where(['id'=>$pay_id])->find();
            $this->assign('jingbanren', cmf_get_admin_name($pay_info['handle']));
            $this->assign('handle_name', cmf_get_admin_name($pay_info['handle']));
            $this->assign('pay_user', cmf_get_admin_name($pay_info['pay_real_name']));
            $this->assign('pay_time', date('Y.d.m',$pay_info['collect_time']));
            $this->finan_print($type);
            return $this->fetch('table'.$type);
        }else{
            //补打
            $this->after_print($type);
        }
    }

    //财务打印
    public function  finan_print($type){
        switch ($type) {
            case 1:
                //礼仪服务单
                break;
            case 2:
                //落葬服务单
                $this->buried();
                break;
            case 3:
                //迁墓服务单
                $this->move();
                break;
            case 4:
                //维保服务单
                $this->weibao();
                break;
            case 5:
                //服务通知单
                break;
            case 6:
                //定金收据
                $other_id = $this->request->param('othid');
                $order_id = $this->request->param('order_id');
                $pay_id = $this->request->param('pay_id');
                $list = Db::name('order_pay_log')->where('id', $pay_id)->find();
                //订金数据（根据other_id查询）
                $deposit_data = Db::name('pay_deposit')->where('id', $other_id)->find();
                $this->getorderinfo($deposit_data['customer_id'], 0);
                if ($list['type'] == 1 && $list['itype'] == 1) {
                    $this->assign('tuikuan', '退定金');
                } else {
                    $this->assign('tuikuan', '预付款');
                }

                $this->assign('jingbanren', cmf_get_admin_name($list['handle']));
                $this->assign('pay_user', cmf_get_admin_name($list['pay_real_name']));
                $this->assign('pay_time', unixtime_to_date(time(), $format = "Y-m-d"));
                $this->assign('list', $list);
                break;
            case 7:
                //服务结算单
                $id = $this->request->param('pay_id');
                $order_pay_info = OrderPayLogModel::where(['id'=>$id])->find();
                $this->assign('handle_name', cmf_get_admin_name($order_pay_info['handle']));
                $this->assign('pay_user', cmf_get_admin_name($order_pay_info['pay_real_name']));
                $this->assign('pay_time', date('Y.d.m',$order_pay_info['collect_time']));
                $custom_id = 0;
                switch ($order_pay_info['itype']) {
                    case 3://落葬
                        $data = Db::name('service_buried')->alias('d')->join(
                            config('prefix') . 'archives_deceased ad', 'ad.deceased_id=d.dead_id', 'left'
                        )->where('d.id', $order_pay_info['other_id'])->find();
                        $custom_id = $data['customer_id'];
                        $list['name'] = '落葬';
                        $list['unitprice'] = '';
                        $list['unit'] = '';
                        $list['num'] = '';
                        $list['price'] = $data['funeral_price'];
                        $price = $data['funeral_price'];
                        break;
                    case 4:
                        //维护
                        $data = Db::name('protect_payment')->where('id', $order_pay_info['other_id'])->find();
                        $list['unitprice'] = $data['manager_price'];
                        $list['name'] = '维护费用';
                        $list['price'] = $data['total_price'];
                        $list['unit'] = '';
                        $list['num'] = '';
                        $custom_id = $order_pay_info['customer_id'];
                        $price = $data['total_price'];
                        $this->assign('if_for', 0);
                        break;
                    case 5:
                        //寄存续费
                        $pay_id = $this->request->param('pay_id');
                        $data = Db::name('order_deposit_send')->where('id', $order_pay_info['other_id'])->find();
                        $order_pay = Db::name('order_pay_log')->where('id', $pay_id)->find();
                        $custom_id = $data['customer_id'];
                        $list['name'] = '寄存续费';
                        $list['unitprice'] = $order_pay['tom_price'];
                        $list['unit'] = '';
                        $list['num'] = $data['storage_time'] . '年';
                        $list['free_price'] = $order_pay['free_price'];
                        $list['price'] = $order_pay['actual_amount'];
                        $nian = intval(($data['total_price'] - $data['original_price']) / $data['original_price']);
                        $list['remark'] = ($data['total_price'] / $data['actual_amount']) != 0 ? "免费寄存{$nian}年" : '';
                        $price = $order_pay['actual_amount'];

                        $this->assign('jingbanren', cmf_get_admin_name($order_pay['handle']));
                        $this->assign('pay_user', cmf_get_admin_name($order_pay['pay_real_name']));
                        $this->assign('pay_time', unixtime_to_date(time(),  "Y-m-d"));
                        $this->assign('if_for', 0);
                        break;
                    case 6:
                        //墓碑刻制
                        $data = Db::name('carve')->where('id', $order_pay_info['other_id'])->find();
                        $carve_arr = explode(',', $data['type']);
                        //碑文制作
                        $list = [];
                        $price = 0;
                        if (in_array('insc', $carve_arr)) {
                            $insc_info = Db::name('carve_insc')->where('carve_id', $data['id'])->find();
                            $remark_position = '';
                            foreach (explode(',',$insc_info['position']) as $key){
                                if ($key==1)$remark_position.= '碑版正面刻字，';
                                elseif ($key==2)$remark_position.= '碑版正面刻字，';
                                elseif ($key==3)$remark_position.= '碑版正面刻字，';
                                elseif ($key==4)$remark_position.= '碑版正面刻字';
                            }

                            $insc['name'] = '碑文刻制';
                            $insc['num'] = 1;
                            $insc['unitprice'] = '';
                            $insc['unit'] = '';
                            $insc['price'] = $insc_info['price'];
                            $insc['remark'] = $insc_info['type']==1?'首刻-':($insc_info['type']==2?'补刻-':($insc_info['type']==3?'重刻':'')).''.$remark_position;;
                            array_push($list, $insc);
                            $price = $price + $insc_info['price'];
                        }
                        //字体贴金
                        if (in_array('gold', $carve_arr)) {
                            $gold_info = Db::name('carve_gold')->where('carve_id', $data['id'])->find();
                            $gold['name'] = '字体贴金';
                            $gold['num'] = 1;
                            $gold['unitprice'] = $gold_info['unitprice'];
                            $gold['unit'] = $gold_info['unit']==1?'平方米':($gold_info['unit']==2?'套':'');
                            $gold['price'] = $gold_info['price'];
                            $gold['remark'] = $gold_info['type']==1?'字体贴金':($gold_info['type']==2?'描金漆':'');
                            array_push($list, $gold);
                            $price = $price + $gold_info['price'];
                        }
                        //磁像制作image
                        if (in_array('image', $carve_arr)) {
                            $image_info = Db::name('carve_image')->where('carve_id', $data['id'])->find();
                            $image['name'] = '瓷像制作';
                            $image['unitprice'] = '';
                            $image['num'] = 1;
                            $image['unit'] = $image_info['shape']==1?'矩形':($image_info['shape']==2?'椭圆形':'');
                            $image['price'] = $image_info['price'];
                            $image['remark'] = $image_info['specificat'].'吋';
                            array_push($list, $image);
                            $price = $price + $image_info['price'];
                        }
                        $this->assign('if_for', 1);
                        $custom_id = $data['customer_id'];
                        break;
                    case 7:
                        //挂失证件工本费
                        $change_info = Db::name('change')->where('id', $order_pay_info['other_id'])->find();
                        $list['name'] = '挂失证件工本费';
                        $list['unitprice'] = $change_info['cost'];
                        $list['unit'] = '本';
                        $list['num'] = 1;
                        $list['price'] = $change_info['cost'];
                        $list['remark'] = $change_info['change_reason']==1?'损毁':($change_info['change_reason']==2?'遗失':'');
                        $custom_id = $change_info['customer_id'];
                        $price = $change_info['cost'];
                        $this->assign('if_for', 0);
                        break;
                }

                $tr_html = '';
                for ($i=2;$i<12-count($list);$i++){
                    $tr_html.=' <tr><td colspan="12"></td></tr>';
                }
                $this->getorderinfo($custom_id, 0);
                $this->assign('list', $list);
                $this->assign('count_num', $tr_html);

                $this->assign('head_title','销售商品结算单');
                $this->assign('operate_name','服务费用（售后服务的收费项目）');
                break;
            case 8:
                //维保结算单
                $id = $this->request->param('order_id');
                $pay_id = $this->request->param('pay_id');
                $weihu = Db::name('service_weibao')->where('id', $id)->find();
                $this->getorderinfo($weihu['customer_id'], 0);
                $this->deposit($pay_id);
                break;
            case 9:
                //销售结算单
                $order_id = $this->request->param('order_id');
                $pay_id = $this->request->param('pay_id');
                $result_goods = Db::name('order_goods')->where('order_id', $order_id)->select()->toArray();
                $this->assign('goods', $result_goods);
                $goods_pricearr = array_column($result_goods, 'total_price');
                $goods_price = array_sum($goods_pricearr);
                $this->assign('goods_price', $goods_price);
                $tr_html='';
                for ($i=count($result_goods)+2;$i<9;$i++){
                    $tr_html.=' <tr><td colspan="8"></td></tr>';
                }

                $pay_info = OrderPayLogModel::where(['id'=>$pay_id])->find();
                $this->assign('pay_user_name', cmf_get_admin_name($pay_info['pay_real_name']));
                $this->assign('pay_time', date('Y.d.m',$pay_info['collect_time']));
                $this->assign('num_count', $tr_html);

                $this->getorderinfo($order_id, 1);
                break;
            case 10:
                //寄存服务单
                $this->register();
                break;
            case 11:
                $pay_id = $this->request->param('pay_id');
                $goods_list = OrderGoodsModel::where(['pay_id'=>$pay_id])->select();
                $list=[];
                foreach ($goods_list as $key=>&$value){
                    $handle_name = cmf_get_admin_name($value['add_user']);
                    $info['name'] =$value['goods_name'];
                    $info['unitprice'] =$value['goods_price'];
                    $info['num'] = $value['num'];
                    $info['unit'] = '';
                    $info['free_price'] = $value['discount_price'];
                    $info['price'] = $value['actual_amount'];
                    $info['remark'] = '';
                    array_push($list, $info);
                }
                $tr_html = '';
                for ($i=2;$i<15-count($list);$i++){
                    $tr_html.=' <tr><td colspan="12"></td></tr>';
                }
                $this->assign('print_title','');
                $this->assign('list',$list);
                $this->assign('num_count',$tr_html);
                $this->assign('head_title','销售商品结算单');
                $this->assign('operate_name','销售-商品');

                break;
            case 12:
                break;
            case 13:
                break;
        }
    }


    //售后打印
    public function  after_print($type){
        $OrderModel = new OrderModel();
        $result = $OrderModel->getRefundOrderBy($this->customerId);
//        $result = $OrderModel->getOrderByCustomerId($this->customerId);
        $buriedModel = new ServiceBuriedModel();
        $buried_list =  $buriedModel->alias('sb')
            ->field('ad.*,sb.dealer_user,sb.handle_name,sb.service_status,sb.id')
            ->join('dj_archives_deceased ad','sb.id=ad.buried_id','left')
            ->where(['sb.order_id'=>$result['order_id']])->select()->toArray();
        $burid[0]=count($buried_list)>=1?$buried_list[0]['deceased_name']:'';
        $burid[1]=count($buried_list)>=2?$buried_list[1]['deceased_name']:'';
        $burid[2]=count($buried_list)>2?$buried_list[2]['deceased_name']:'';
        $this->assign('burid',$burid);
        $this->assign('result',$result);

        if($type==1){
            //礼仪服务单
        }else if($type==2){
            //落葬服务单
            $this->buried();
        }else if($type==3){
            //迁墓服务单
            $this->move();
        }else if($type==4){
            //维保服务单
            $this->weibao();
        }else if ($type==5){
            //服务通知单
        }else if ($type==6){
            //定金收据
            $order_id=$this->request->param('order_id');
            $pay_id =  $this->request->param('pay_id');
            $list =Db::name('order_pay_log')->where('id',$pay_id)->find();
            //订金数据（根据other_id查询）
            $deposit_data=Db::name('pay_deposit')->where('id',$order_id)->find();
            $this->getorderinfo($deposit_data['customer_id'],0);
            $this->assign('list',$list);
        }else if ($type==7){
            //服务结算单
            $id =  $this->request->param('pay_id');
            $this->assign('if_for',1);
            $itype =  $this->request->param('itype');
            $pay_info =Db::name('order_pay_log')->where('id',$id)->find();
            $customer_id = $pay_info['customer_id'];
            $list_arr=[];
            switch ($pay_info['itype']){
                case 3:
                    //落葬
                    $list =  $buriedModel->alias('sb')
                        ->field('ad.*,sb.dealer_user,sb.handle_name,sb.service_status,sb.id')
                        ->join('dj_archives_deceased ad','sb.id=ad.buried_id','left')
                        ->where(['sb.order_id'=>$result['order_id']])->select();
                    $price=0;
                    foreach($list as $key=>$vo){
                        $info['name']='落葬';
                        $info['unitprice']='';
                        $info['unit']='';
                        $info['num']='';
                        $info['price']=$vo['funeral_price'];
                        $list_arr[] = $info;
                        $price=$price+$vo['funeral_price'];
                    }
                    break;
                case 4:
                    //维护
                    $ProtectPayModel = new ProtectPaymentModel();
                    $list = $ProtectPayModel ->where(['customer_id'=>$customer_id,'pay_id'=>$id])->order('id desc')->select();
                    $price=0;
                    foreach($list as $key=>$vo){
                        $info['unitprice']=$vo['manager_price'];
                        $info['name']='维护费用';
                        $info['price']=$vo['total_price'];
                        $info['unit']='';
                        $info['num']='';
                        $list_arr[] = $info;
                        $price=$vo['total_price']+$price;
                    }
                    $this->assign('if_for',1);
                    break;
                case 5:
                    //寄存续费
//                $pay_id=$this->request->param('pay_id');
//                $data=Db::name('order_deposit_send')->where('id',$order_pay_info['other_id'])->find();
//                $order_pay=Db::name('order_pay_log')->where('id',$pay_id)->find();
//                $custom_id=$data['customer_id'];
//                $list['name']='寄存续费';
//                $list['unitprice']=$order_pay['tom_price'];
//                $list['unit']='';
//                $list['num']='';
//                $list['price']=$order_pay['total_price'];
//                $price=$data['price'];
                    break;
                case 6:
                    //墓碑刻制
                    $data = Db::name('carve')->where(['tomb_id'=>$result['tomb_id'],'customer_id'=>$customer_id])->order('id desc')->limit(1)->select()->toArray();
                    $carveid_arr=array_column($data,'id');
//                $carve_arr=explode(',',$data['type']);
                    //碑文制作
                    $list=[];
                    $price=0;
                    $lists=Db::name('carve_insc')->whereIn('carve_id',$carveid_arr)->select();
                    foreach ($lists as $vo){
                        $vo['name']='碑文刻制';
                        $vo['unitprice']='';
                        $vo['unit']='';
                        $vo['num']=1;
                        $list_arr[] = $vo;
                        array_push($list,$vo);
                        $price=$price+$vo['price'];
                    }
                    //字体贴金
                    $lists=Db::name('carve_gold')->whereIn('carve_id',$carveid_arr)->select();
                    foreach ($lists as $vo){
                        $vo['name']='字体贴金';
                        $vo['num']=1;
//                    $vo['unitprice']=$vo['unitprice'];
//                    $vo['unit']=$vo['unit'];
//                    $vo['price']=$list['price'];
                        $list_arr[] = $vo;
                        $price=$price+$vo['price'];
                    }

                    //磁像制作image
                    $lists=Db::name('carve_image')->whereIn('carve_id',$carveid_arr)->select();
                    foreach($lists as $vo){
                        $vo['name']='瓷像制作';
                        $vo['unitprice']='';
                        $vo['num']=1;
                        $vo['unit']=$vo['shape'];
                        $list_arr[] = $vo;
                        $price=$price+$vo['price'];
                    }
                    $this->assign('if_for',1);
                    break;
                case 7:
                    //挂失证件工本费
                    $log_list = Db::name('change')->alias('ad')
                        ->field('ad.*,u.user_nickname,c.cart_upload as old_cart_upload')
                        ->leftJoin('dj_user u','u.id = ad.add_user')
                        ->leftJoin('dj_customer_info c','c.id = ad.customer_id')
                        ->select()->toArray();
                    $price=0;
                    foreach ($log_list as $key => $val){
                        $log_list[$key]['type_name'] = $val['type'] == 1?"变更":"挂失";
                        $log_list[$key]['change_reason'] = $val['change_reason'] == 0?"原因1":"-";
                        $Info['name']=$log_list[$key]['type_name'].'证件工本费';
                        $Info['unitprice']=$val['cost'];
                        $Info['unit']='本';
                        $Info['num']=1;
                        $Info['price']=$val['cost'];
                        $list_arr[] = $Info;
                        $price=$val['cost']+$price;
                    }
                    $this->assign('if_for',1);
                    break;
            }
            $this->assign('list',$list);
            $this->assign('price',$price);
            $html=$this->fetch('table7')->getContent();
            echo json_encode(['status'=>1,'html'=>$html]);
        }else if ($type==8){
            //维保结算单
            $id=$this->request->param('weibao');
            $list=Db::name('maintenance_project')->whereIn('wb_id',$id)->select()->toArray();
            $price_arr=array_column($list,'total_price');
            $price=array_sum($price_arr);
            $this->assign('price',$price);
            $this->assign('list',$list);
            $html=$this->fetch('table8')->getContent();
            echo json_encode(['status'=>1,'html'=>$html]);

        }else if ($type==9){
            //销售结算单
            $order_id=$this->request->param('order_id');
            $result_goods = Db::name('order_goods')->where('order_id',$order_id)->select()->toArray();
            $this->assign('goods',$result_goods);
            $goods_pricearr=array_column($result_goods,'total_price');
            $goods_price=array_sum($goods_pricearr);
            $this->assign('goods_price',$goods_price);
            $this->getorderinfo($order_id,1);
        }else if($type==10){
            //寄存服务单
            $this->register();
        }else if($type==11){

            $this->assign('head_title','');
            $this->assign('operate_name','');
        }else if($type==12){
        }
    }



    //订单详细信息
    public  function  getorderinfo($order_id,$type=0){
        $order_id=$order_id==148?114:$order_id;
        $OrderModel = new OrderModel();
        $result = $OrderModel->getRefundOrderBy($order_id,$type);
//        $result = $OrderModel->getOrderByCustomerId($order_id,$type);
        $result['pro_status'] = $this->col_status[$result['pro_status']];
        $result['handle_name'] = cmf_get_admin_name($result['handle']);
        $this->assign('result',$result);
    }

    //落葬单
    public  function buried(){
        $model = new ServiceBuriedModel();//Db::name("serviceBuried");
        $id = $this->request->param('id');
        $list=$model->alias('d')->field('u.user_nickname,d.order_id,d.dead_id,d.dealer_phone,d.buried_time,d.add_time,d.customer_id,a.date_funeral,a.funeral_time,a.cremation_certificate,a.receptionist')->
        join(config('prefix').'archives_deceased a','a.deceased_id=d.dead_id','left')
        ->join(config('prefix').'user u','a.receptionist=u.id','left')
            ->where('d.id',$id)->find();
        $list['buried_date']=date('Y-m-d',$list['buried_time']);
        $list['buried_time']=date('H:i',$list['buried_time']);
        $list['add_time']=date('Y-m-d',$list['add_time']);
        $this->get_info($list['order_id'],1);

        $this->assign('list',$list);
        $this->assign('head_title','');
        $this->assign('operate_name','');
    }
    //迁墓服务单
    public  function move(){
        $model = Db::name("serviceMove");
        $id = $this->request->param('id');
        $list=$model->alias('d')
            ->field('d.receptionist,d.add_time,d.add_user,d.buyer_phone,d.tombstone_plan,d.handle_id,d.move_time,d.customer_id,u.user_nickname,d.death_name')
            ->join(config('prefix').'user u','d.receptionist=u.id','left')
            ->where('d.id',$id)->find();
        $list['move_date']=date('Y-m-d',$list['move_time']);
        $list['move_time']=date('H:i',$list['move_time']);
        $list['add_time']=date('Y-m-d',$list['add_time']);
        $this->get_info($list['customer_id'],0);

        $death_name = $list['death_name'];
        if(!empty($death_name)){
            $buried_list = explode(' ',$death_name);
            $burid1[0]=count($buried_list)>=1?$buried_list[0]:'';
            $burid1[1]=count($buried_list)>=2?$buried_list[1]:'';
            $burid1[2]=count($buried_list)>2?$buried_list[2]:'';

            $this->assign('burid1',$burid1);
        }


        $this->assign('list',$list);
    }


    //维保服务单
    public  function  weibao(){
        $WeibaoModel    = new ServiceWeibaoModel();
        $MaintenanceProjectModel    = new MaintenanceProjectModel();
        $id = $this->request->param('id',99);
        $mb = $this->request->param('mb',0);
        //维护详情数据
        if ($mb==1){
            $list = $MaintenanceProjectModel->alias('wp')
                ->field('wp.*,pm.pro_name')
                ->leftJoin(config('prefix').'product_mb pm','wp.pro_id = pm.id')
                ->where(['wp.wb_id'=>$id])->select();
        }else{
            $list = $MaintenanceProjectModel->where(['wb_id'=>$id])->select();
        }
        //维保时间和接单人
        $weibao=$WeibaoModel->alias('d')->field(
            'd.id,d.deliver_time,d.handle_id,d.handle_name,d.service_status,d.add_user,d.type,d.customer_id'
        )->where(['d.id'=>$id])->find();
        if(!empty($weibao['deliver_time'])) {
            $weibao['deliver_time'] = date('Y-m-d', $weibao['deliver_time']);
        }
        $this->assign('weibao',$weibao);
        //获取共同信息
        $this->get_info($weibao['customer_id']);
        foreach ($list as $k=>&$value){
            if($value['expedited'] == 1){
                $value['if_jiaji']='是';
            }else{
                $value['if_jiaji']='否';
            }
            if ($value['total_price'] == 0) {
                $value['warranty_type']= '更换';
            }else{
                $value['warranty_type']= '维修';
            }
            $value['deliver_time'] = date('Y-m-d',$value['deliver_time']);
        }
        $this->assign('list',$list);
    }

    public  function  deposit($pay_id){
        $list = MaintenanceProjectModel::where(['pay_id'=>$pay_id])->select()->toArray();
        $price_arr=array_column($list,'total_price');

        $price=array_sum($price_arr);
        $this->assign('price',$price);
        $this->assign('list',$list);
    }

    //共同的头部尾部信息
    public  function  get_info($user_id,$type=0){
        $OrderModel = new OrderModel();
        $result = $OrderModel->getRefundOrderBy($user_id,$type);
//        $result = $OrderModel->getOrderByCustomerId($user_id,$type);
        $buriedModel = new ServiceBuriedModel();
        $buried_list =  $buriedModel->alias('sb')
            ->field('ad.*,sb.dealer_user,sb.handle_name,sb.service_status,sb.id')
            ->join('dj_archives_deceased ad','sb.id=ad.buried_id','left')
            ->where(['sb.order_id'=>$result['order_id']])
            ->select()->toArray();
        $burid[0]=count($buried_list)>=1?$buried_list[0]['deceased_name']:'';
        $burid[1]=count($buried_list)>=2?$buried_list[1]['deceased_name']:'';
        $burid[2]=count($buried_list)>2?$buried_list[2]['deceased_name']:'';
        $this->assign('burid',$burid);
        $this->assign('result',$result);
    }

    //寄存
    public function  register(){
        $id=$this->request->param('id');
        $jicun=Db::name('service_deposit')->where('id',$id)->find();
        $deceased_list = Db::name('archives_deceased')->alias('ad')
            ->field('ad.*,od.deposit_time,od.id deposit_id')
            ->leftJoin('dj_order_deposit od','od.id = ad.deposit_id')
            ->where(['ad.tomb_id'=>$jicun['tomb_id'],'od.customer_id'=>$jicun['customer_id']])->find();
        $deceased_list['deposit_date']=date('Y-m-d',$deceased_list['deposit_time']);
        $deceased_list['deposit_time']=date('H:i',$deceased_list['deposit_time']);
        $deceased_list['dealer_phone']=$jicun['dealer_phone'];
        $deceased_list['dead_name']=$jicun['dead_name'];
        $this->get_info($jicun['customer_id']);
        $this->assign('list',$deceased_list);
    }




    //共同的头部尾部信息
    public  function  getTopInfo($id,$type=0)
    {
        $OrderModel = new OrderModel();
        $result = $OrderModel->getRefundOrderBy($id,$type);


        $array_top['buyer_name'] = $result['buyer_name'];
        $array_top['buyer_phone'] = $result['buyer_phone'];
        $array_top['tomb_num'] = $result['tomb_num'];
        $array_top['tomb_region'] = $result['tomb_region'].$result['tomb_address'].$result['tomb_bit_number'];
        $array_top['tomb_regulation'] = $result['tomb_regulation'];
        $array_top['tomb_regulation_name'] = $result['tomb_regulation_name'];
        $array_top['col_status_name'] = $result['col_status_name'];
//        //逝者
//        $array_top['deceased_name_1'] = count($buried_list)>=1?$buried_list[0]['deceased_name']:'';
//        $array_top['deceased_name_2'] = count($buried_list)>=2?$buried_list[1]['deceased_name']:'';
//        $array_top['deceased_name_3'] = count($buried_list)>=2?$buried_list[2]['deceased_name']:'';
//        $array_top['cremation_certificate_1'] = count($buried_list)>=1?!empty($buried_list[0]['cremation_certificate'])?"√":'×':'×';
//        $array_top['cremation_certificate_2'] = count($buried_list)>=2?!empty($buried_list[1]['cremation_certificate'])?"√":'×':'×';
//        $array_top['cremation_certificate_3'] = count($buried_list)>=2?!empty($buried_list[2]['cremation_certificate'])?"√":'×':'×';

        return $array_top;
    }

}